// 判断账户是否登录  标识变量 点击是否要确认退出登录的判断
function Login (){}
$.extend(Login.prototype,{
    init:function(){
        this.list = localStorage.getItem("user");
        this.login = $(".login");
        this.login_show =$(".login_show");
        this.username = $(".userName");
        this.show();
        this.username.on("click",$.proxy(function(){
            var flag = confirm("是否要退出登录？")
            this.quit(flag);
        },this))
    },
    show:function(){
        if(!this.list){
            this.login.css("display","block");
            this.login_show.css("display","none");
        }else{
            var list = JSON.parse(this.list);
            var flag = false;
            $.each(list,$.proxy(function(index,item){
                if(item.status){
                    this.login.css("display","none");
                    this.login_show.css("display","block");
                    this.username.html(item.user);
                    flag = true;
                    return false;
                }
            },this))
            if(!flag){
                this.login.css("display","block");
                this.login_show.css("display","none");
            }
        }
    },
    // 确认退出的话  需要改变状态
    quit : function(flag){
        if(flag){
            var list = JSON.parse(this.list);
            $.each(list,$.proxy(function(index,item){
                if(item.user == this.username.html()){
                    item.status = false;
                    localStorage.setItem("user",JSON.stringify(list));
                    location.reload(true);
                }
            },this))
        }
    }
})

export default new Login();